package com.antipov.odp;

import com.antipov.odp.pojo.A;
import com.antipov.odp.pojo.B;
import com.antipov.odp.pojo.C;
import com.antipov.odp.pojo.I;

import java.io.IOException;
import java.util.Random;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: Andrew Antipov
 * Date: 18.02.14
 * Time: 22:33
 */
public class DataCreator {

	private static Random random = new Random();

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		if(x <= 0 || x % 2 != 0) {
			throw new IllegalArgumentException();
		}
		I[] data = new I[x];
		for(int i = 0; i < x; i++) {
			data[i] = createRandomI();
		}
		String fileName = sc.next();
		try {
			IOHelper.saveData(data, fileName);
		} catch (IOException e) {
			System.err.println("Failed to save");
			e.printStackTrace();
		}
	}

	public static I createRandomI() {
		int type = random.nextInt(3) + 1;
		int arrayLength = random.nextInt(10) + 1;
		int[] array = new int[arrayLength];
		for(int i = 0; i < arrayLength; i++) {
			array[i] = random.nextInt(10);
		}
		int x = random.nextInt(100);
		switch (type) {
			case A.ID:
				return new A(array, x);
			case B.ID:
				double d = random.nextDouble();
				return new B(array, x, d);
			case C.ID:
				char c = (char) ('a' + random.nextInt(26));
				return new C(array, x, c);
		}
		throw new RuntimeException();
	}

}
